DEPTH = ../..

include $(DEPTH)/scripts/Makefile

SRCS        = SQLiteDemo.cxx
DATABASE    = demo.sqlite
DATAFILE    = sample_data.sql
TABLE_NAME  = a

demo: clean all new_database insert_sample_data show_data

all: SQLiteDemo

SQLiteDemo: $(SRCS)
	@$(SCRIPTS_DIR)/progress 'Building Demo'
	$(GPP) $(CFLAGS) $? $(LDFLAGS) -o $@

clean:
	@$(SCRIPTS_DIR)/progress 'Cleaning'
	rm -f SQLiteDemo
	rm -f $(DATABASE)

new_database: all
	@$(SCRIPTS_DIR)/progress 'Creating new database and table'
	./SQLiteDemo "$(DATABASE)" "CREATE TABLE '$(TABLE_NAME)' ('c' int)"

insert_sample_data: all
	@$(SCRIPTS_DIR)/progress 'Inserting sample rows'
	xargs -tI {} ./SQLiteDemo "$(DATABASE)" "{}" < $(DATAFILE) 2>&1

show_data: all
	@$(SCRIPTS_DIR)/progress 'Displaying contents of table'
	./SQLiteDemo "$(DATABASE)" "SELECT * FROM $(TABLE_NAME)"
